package jjn.acwing.algorithm_basic.chapter1.two_pointer;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author Jiang Jining
 * @since 2023-09-22 22:04
 */
public class Acwing799 {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String readLine = bufferedReader.readLine();
        int n = Integer.parseInt(readLine);
        String line = bufferedReader.readLine();
        String[] parts = line.split(" ");
        int[] nums = new int[10010];
        int[] s = new int[10010];
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(parts[i]);
        }
        int res = 0;
        for (int i = 0, j = 0; i < n; i++) {
            s[nums[i]]++;
            while (j < i && s[nums[i]] > 1) {
                s[nums[j]]--;
                j++;
            }
            res = Math.max(res, i - j + 1);
        }
        System.out.println(res);
    }
}
